<template>
  <div style="height: 80vh;">
    <SnakerFlowDesigner class="m-snaker-flow-designer" v-model="flowData" @on-save="handleSave" />
  </div>
</template>
<script>
import { get as getModelDesigner, saveDefine } from '@/api/wf/wf.modelDesigner.service.js'
export default {
  props: {
    isEdit: {
      type: Boolean,
      default: false
    },
    isTree: {
      type: Boolean,
      default: false
    },
    id: {
      type: [String, Number],
      default: undefined
    }
  },
  data() {
    return {
      flowData: ''
    }
  },
  created() {
    getModelDesigner({
      id: this.id
    }).then(res => {
      if (res.code === 0) {
        this.flowData = res.data.xml
      }
    })
  },
  methods: {
    // 保存
    handleSave(data) {
      saveDefine({
        modelDesignerId: this.id,
        content: data.xml
      }).then(res => {
        if (res.code === 0) {
          this.$message.success('保存成功')
        } else {
          this.$message.error(res.msg || '保存失败')
        }
      })
    }
  }
}
</script>
